home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3787 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: ix.netcom.com!netnews
  2. From: miker3@ix.netcom.com (Mike Rubenstein)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Beginner: How to #include
  5. Date: Wed, 31 Jan 1996 02:14:29 GMT
  6. Organization: Netcom
  7. Message-ID: <310ecfc8.10036800@nntp.ix.netcom.com>
  8. References: <west.31.00844D6A@emt.e-technik.tu-muenchen.de>
  9. NNTP-Posting-Host: ix-dc9-11.ix.netcom.com
  10. X-NETCOM-Date: Tue Jan 30  6:15:00 PM PST 1996
  11. X-Newsreader: Forte Agent .99c/16.141
  12.  
  13. west@emt.e-technik.tu-muenchen.de (Robert Westendorp) wrote:
  14.  
  15. > Hi there,
  16. > I've got a principle question:
  17. > I've got a project which consists of a couple of files.
  18. > Let's say I define a struct including a member which is of a type 
  19. > declared in direct.h
  20. > First File: my_inc.h
  21. > #include <direct.h>
  22. > struct MYSTRUCT
  23. > {
  24. >     _find_t fileinfo;
  25. > ....
  26. > }
  27. > Then I want to use this struct in another file: 
  28. > struct MYSTRUCT my_variable;
  29. > I will have to include my_inc.h, AND I will have to include direct.h;
  30. > Now I have a couple of include files and it's very annoying always to include
  31. > those files down to direct.h, especially because I have to include them in the 
  32. > right order.
  33. > How can I solve this problem?
  34. > Include in include-files???
  35.  
  36. That's how I do it.  With rare exceptions, every file includes all the
  37. headers it needs to declare things it uses.
  38.  
  39. There's one problem you need to handle.  Sometimes including a file
  40. twice will cause errors.  The way to handle this is to protect with
  41. #if.  For example, the header myheader.h might look something like:
  42.  
  43.     #if !defined MYHEADER_H
  44.     #define MYHEADER_H
  45.     /* ... */
  46.     #endif
  47.  
  48.  
  49. Michael M Rubenstein
  50.